package cn.edu.cuit.aumalls.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import cn.edu.cuit.aumalls.service.UserRegisterService;

@Controller
public class RegisterController {
	
	@Autowired
	private UserRegisterService userRegisterService;
	
	
	@RequestMapping("/toregister")
	public String toRegister() {
		
		return "register";
	}
	
	@RequestMapping("/register")
	public String register(@RequestParam("username")String username,
			@RequestParam("password")String password,
			@RequestParam("userphone")String userphone,
			@RequestParam("useraddress")String useraddress,Model model) {
		
		boolean ref =  userRegisterService.InsertUser(username, password, userphone, useraddress);
		if(ref) {
			model.addAttribute("success", "注册成功！");
			return "regsuccess";
		}
		else {
			model.addAttribute("registerErrorMsg", "注册失败");
			return "register";
		}
	}
}
